package com.mf.all.controller;


import com.mf.all.entity.req.publicReq.updateStatus.ReqPublicIntIdUpdateStatus;
import com.mf.all.groups.GroupsAddInterface;
import com.mf.all.groups.GroupsUpdateInterface;
import com.mf.all.result.Result;
import com.mf.all.utils.UtilController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.all.entity.dto.DtoWarehouse;
import com.mf.all.entity.req.ReqWarehouse;
import com.mf.all.service.ServiceWarehouse;
import com.mf.all.entity.req.search.SearchReqWarehouse;

import java.util.Arrays;
import java.util.List;

/**
 * 仓库管理
 *
 * @date 2025-04-02 22:36:45
 */
@RestController
@RequestMapping("warehouse")
@Tag(name = "仓库管理")
public class ControllerWarehouse {
    @Resource
    private ServiceWarehouse servicewarehouse;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    @SaCheckPermission("warehouse:search")
    public Result<Page<DtoWarehouse>> findPage(@RequestBody SearchReqWarehouse searchReqWarehouse) {
        return Result.success(servicewarehouse.findPageByParams(searchReqWarehouse));
    }

    @Operation(summary = "列表查询")
    @PostMapping("/list")
    @SaCheckPermission("warehouse:search")
    public Result<List<DtoWarehouse>> list(@RequestBody SearchReqWarehouse searchReqWarehouse) {
        return Result.success(servicewarehouse.findListByParams(searchReqWarehouse));
    }


    @Operation(summary = "保存")
    @PostMapping("/save")
    @SaCheckPermission("warehouse:save")
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqWarehouse reqWarehouse) {
        servicewarehouse.save(UtilController.setBo(reqWarehouse, DtoWarehouse.class));
        return Result.success();
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    @SaCheckPermission("warehouse:update")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqWarehouse reqWarehouse) {
        servicewarehouse.updateById(UtilController.setBo(reqWarehouse, DtoWarehouse.class));
        return Result.success();
    }

    @Operation(summary = "删除")
    @PostMapping("/delete")
    @SaCheckPermission("warehouse:delete")
    public Result<Void> delete(@RequestBody Integer[] ids) {
        servicewarehouse.removeByIds(Arrays.asList(ids));
        return Result.success();
    }

    @Operation(summary = "修改状态")
    @PostMapping("/updateStatus")
    @SaCheckPermission("warehouse:status")
    public Result<Void> updateStatus(@Validated @RequestBody ReqPublicIntIdUpdateStatus updateStatus) {
        servicewarehouse.updateById(UtilController.setBo(updateStatus, DtoWarehouse.class));
        return Result.success();
    }

}
